
fetch("http://chst.vip:1234/api/getcategorytitle")
    .then(body => body.json())
    .then(res => {
        // console.log(res);
        let html = ''
        let arr = []
        let idx = 0
        let flag = null;
        let flag2 = false;
        //▲▼▼
        res.result.forEach(item => {
            html += `<li titleId = ${item.titleId} index = ${idx}>
              <span>${item.title}</span>
              <span>▼</span>
        </li><div class="box2"></div>`
            arr.push(item.titleId)
            idx++
        });
        $("#uu")[0].innerHTML = html
        fn(arr)//一堆的div信息
        $("#uu>li").click(function () {
            let index = this.getAttribute('index')
            //http://chst.vip:1234/api/getcategory?titleid=0
            
            $("#uu").find('.box2').stop().hide(500).end()
            .find('.box2').eq(index).stop().show(500)
            
            if (this === flag) {
                if(flag2){
                    // console.log(1);
                    $("#uu").find('.box2').stop().hide(500).end()
                    .find('.box2').eq(index).stop().show(500)
                    flag2 = false
                }else{
                    // console.log(2);
                    $("#uu").find('.box2').stop().hide(500)
                    flag2 = true
                }
            }else{
                flag2 = false
            }

            $(this).next().find('nav').click(function(){
                let categoryid = this.getAttribute('categoryid')
                let pageid = this.getAttribute('pageid')
                // console.log(this.innerText);
                location.href = `./bijia.html?categoryid=${categoryid}&title=${this.innerText}`
            })
            flag = this
        })


        function fn(arr) {
            let i = 0
            function fn2(i) {
                if (i >= arr.length) {
                    return
                }
                fetch(`http://chst.vip:1234/api/getcategory?titleid=${arr[i]}`)
                    .then(body => body.json())
                    .then(res2 => {
                        console.log(res2);
                        let html2 = ""
                        res2.result.forEach(item => {
                            html2 += `                     
                        <nav class = 'xdiv' categoryid = ${item.categoryId} pageid = ${item.titleId}>
                        <p class="ellipsis">${item.category}</p>
                        </nav>
                        `
                        })
                        $(".box2")[i].innerHTML = html2
                        i++;
                        fn2(i)
                    })
            }
            fn2(i)

        }

    })
